clear all
set more off

local path0="C:\Dropbox\GeneticsProject (1)\REStat\round_accepted_replication_files\"


cd "`path0'Workfiles"

insheet using "`path0'Data\PennWorldTables\PWT62.csv", names clear

destring year pop xrat ppp cgdp cc cg ci p pc pg pi openc cgnp y rgdpl rgdpch rgdpeqa rgdpwok rgdptt openk kc kg ki grgdpch, replace force

label var  pop  "PWT: Population"
label var  xrat "PWT: Exchange Rate"
label var  ppp  "PWT: Purchasing Power Parity over GDP"
label var  cgdp "PWT: Real Gross Domestic Product per Capita"
label var  cc   "PWT: Consumption Share of CGPD"
label var  cg   "PWT: Government Share of CGDP"
label var  ci   "PWT: Investment Share of CGDP"
label var  p    "PWT: Price Level of Gross Domestic Product"
label var  pc   "PWT: Price Level of Consumption"
label var  pg   "PWT: Price Level of Government"
label var  pi   "PWT: Price Level of Investment"
label var  openc "PWT:  Openness in Current Prices"
label var  cgnp  "PWT: Ratio of GNP to GDP"
label var  y     "PWT: CGDP Relative to the United States"
label var  rgdpl   "PWT: Real GDP per capita (Constant Prices: Laspeyres)"
label var  rgdpch  "PWT: Real GDP per capita (Constant Prices: Chain series)"
label var  rgdpeqa "PWT: Real GDP Chain per equivalent adult"
label var  rgdpwok "PWT: Real GDP Chain per worker"
label var  rgdptt  "PWT: Real Gross Domestic Income (RGDPL adjusted for Terms of Trade changes)"
label var  openk   "PWT: Openness in Constant Prices"
label var  kc  "PWT: Consumption Share of RGDPL"
label var  kg  "PWT: Government Share of RGDPL"
label var  ki  "PWT: Investment Share of RGDPL"
label var  grgdpch "PWT: growth rate of Real GDP per capita (Constant Prices: Chain series)"


foreach var in pop xrat ppp cgdp cc cg ci p pc pg pi openc cgnp y rgdpl rgdpch rgdpeqa rgdpwok rgdptt openk kc kg ki grgdpch {
	rename `var' pwt_`var'
}

rename countryisocode countrycode

compress
save PWT_raw, replace

*========================================================================
*			prepate only relevant data
*========================================================================

gen pwt_ln_rgdpch=log(pwt_rgdpch) if year==2000
label var pwt_ln_rgdpch  "PWT: LOG Real GDP per capita (Constant Prices: Chain series): year=2000"

gen pwt_ln_rgdpeqa =log(pwt_rgdpeqa) if year==2000
label var  pwt_ln_rgdpeqa "PWT: LOG Real GDP Chain per equivalent adult: year=2000"

gen pwt_ln_rgdpwok =log(pwt_rgdpwok) if year==2000
label var  pwt_ln_rgdpwok "PWT: LOG Real GDP Chain per worker: year=2000"


* compute growth rate for every decade
foreach var in pwt_rgdpch pwt_rgdpeqa pwt_rgdpwok {
	foreach timet in 1950 1960 1970 1980 1990 2000 {
		gen  temp0_`var'_`timet'=log(`var') if year==`timet'
		egen temp1_`var'_`timet'=max(temp0_`var'_`timet'), by(countrycode)
	}
}

foreach var in rgdpch rgdpeqa rgdpwok {
	foreach timet in 50 60 70 80 90 {
		gen pwt_g`timet'_`var'=(temp1_pwt_`var'_2000-temp1_pwt_`var'_19`timet')/(2000-1900-`timet')
		label var pwt_g`timet'_`var' "PWT: `var': average growth rate between 19`timet' and 2000"
	}
}

foreach var in rgdpch rgdpeqa rgdpwok {
	foreach timet in 50 60 70 80 90 {
		gen pwt_`timet'_`var'=temp1_pwt_`var'_19`timet'
		label var pwt_`timet'_`var' "PWT: `var': level of output per worker in 19`timet'"
	}
}


drop temp*
keep if year==2000
drop year
compress
keep countrycode pwt_ln_rgdpwok
save PWT_for_merge, replace
	




